<?php

/**
 * This is the model class for table "tbl_comment_collection".
 *
 * The followings are the available columns in table 'tbl_comment_collection':
 * @property string $id
 * @property string $content
 * @property string $user_id
 * @property string $comment_at
 * @property string $collection_id
 * @property integer $status
 *
 * The followings are the available model relations:
 * @property Collection $collection
 * @property User $user
 */
class CommentCollection extends CActiveRecord {

    const COMMENT_LOCKED = 0;
    const COMMENT_ACTIVE = 1;

    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return Comment the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'tbl_comment_collection';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('content, user_id, comment_at, collection_id', 'required'),
            array('status', 'numerical', 'integerOnly' => true),
            array('content', 'length', 'max' => 300),
            array('user_id, collection_id', 'length', 'max' => 20),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, content, user_id, comment_at, collection_id, status', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'collection' => array(self::BELONGS_TO, 'Collection', 'collection_id'),
            'user' => array(self::BELONGS_TO, 'User', 'user_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'id' => 'ID',
            'content' => 'Content',
            'user_id' => 'User',
            'comment_at' => 'Comment At',
            'collection_id' => 'Collection',
            'status' => 'Status',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('content', $this->content, true);
        $criteria->compare('user_id', $this->user_id, true);
        $criteria->compare('comment_at', $this->comment_at, true);
        $criteria->compare('collection_id', $this->collection_id, true);
        $criteria->compare('status', $this->status);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
                ));
    }

}